/*package com.neo.redis;
package com.neo.shiro;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

public class ShiroCache<K, V> implements Cache<K, V>{

	private Logger logger = LoggerFactory.getLogger(ShiroCache.class);
	private static final String REDIS_SHIRO_CACHE = "junson-shiro-cache:";
    private String cacheKey;
    
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;
    
    private final long globExpire = 3;
    
    
    
	public ShiroCache(String cacheKey, RedisTemplate<Object, Object> redisTemplate) {
		super();
		this.cacheKey = REDIS_SHIRO_CACHE + cacheKey + ":";
		this.redisTemplate = redisTemplate;
	}

	@Override
	public void clear() throws CacheException {
		logger.debug("==>清空缓存");
		redisTemplate.delete(keys());
	}

	@SuppressWarnings("unchecked")
	@Override
	public V get(K key) throws CacheException {
		redisTemplate.boundValueOps(getCacheKey(key)).expire(globExpire, TimeUnit.MINUTES);
		V v = (V) redisTemplate.boundValueOps(getCacheKey(key)).get();
		logger.debug("==>获取缓存 [key]:" + getCacheKey(key) + "[value]:" + v);
        return v;
	}

	@SuppressWarnings("unchecked")
	private Object getCacheKey(Object key) {
		return (K) (this.cacheKey + key);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Set<K> keys() {
		return (Set<K>) redisTemplate.keys(getCacheKey("*"));
	}

	@Override
	public V put(K key, V value) throws CacheException {
		logger.debug("==>写入缓存 [key]:" + getCacheKey(key) + "[value]:" + value);
		V old = get(key);
        redisTemplate.boundValueOps(getCacheKey(key)).set(value);
        return old;
	}

	@Override
	public V remove(K key) throws CacheException {
		logger.debug("==>删除缓存 [key]:" + getCacheKey(key));
		V old = get(key);
        redisTemplate.delete(getCacheKey(key));
        logger.debug("==>old key:" + getCacheKey(key));
        return old;
	}

	@Override
	public int size() {
		logger.debug("==>[size]:"+keys().size());
		return keys().size();
	}

	@Override
	public Collection<V> values() {
		Set<K> set = keys();
		logger.debug("==>[Collection]:" + set.size());
        List<V> list = new ArrayList<>();
        for (K s : set) {
            list.add(get(s));
        }
        return list;
	}

}
*/